package controller

import (
	"ginfast/api/system/dto"
	"ginfast/api/system/model"
	"ginfast/api/system/service"
	"ginfast/pkg/dao"
	"ginfast/pkg/gctx"

	"github.com/gin-gonic/gin"
)

// LoginLog
type LoginLog struct {
}

// ListHandler 列表
func (LoginLog) ListHandler(c *gin.Context) {
	var p dto.Where
	if err := c.ShouldBind(&p); err != nil {
		gctx.JSONWriteError(err, c)
		return
	}
	var data []model.SysLoginLog
	total, _ := p.DbModelWhere(&model.SysLoginLog{}).Find(&data)
	gctx.JSONWrite(gin.H{"data": data, "total": total}, c)
}

// DeleteHandler 删除
func (LoginLog) DeleteHandler(c *gin.Context) {
	dao.Deletes(&model.SysLoginLog{}, c)
}

// ClearHandler 清空
func (LoginLog) ClearHandler(c *gin.Context) {
	service.Clear(&model.SysLoginLog{}, c)
}

func (o LoginLog) Router(r *gin.RouterGroup) {
	r.GET("/list", o.ListHandler)
	r.DELETE("/:id", o.DeleteHandler)
	r.DELETE("/clear", o.ClearHandler)
}
